<?php

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#	FILE:			includes/format/admin.php
#	FUNCTION:		Formatting the admin page output
#	AUTHOR:			Cameron Morrow
#	CREATED:		27/07/2005
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# S T A R T   H T M L
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-AU\" xml:lang=\"en-AU\">\n";
echo "<!-- Created by Cameron Morrow for Zone 4 -->\n";
echo "<head>\n";
echo "\t<title>" . $PROJECT_TITLE . " - " . $PAGE_NAME . "</title>\n";
echo "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
echo "\t<script language=\"javascript\" type=\"text/javascript\" src=\"../assets/scripts/admin.js\"></script>\n";
echo "\t<script src=\"../assets/scripts/multifile_compressed.js\"></script>\n";
echo "\t<style type=\"text/css\">\n";
echo "\t\t@import url(\"../assets/styles/black.css\");\n";
echo "\t</style>\n";
header('Access-Control-Allow-Origin: *');
echo "</head>\n";

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# B O D Y
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "<body class=\"" . ($PAGE_COMPACT ? "compact" : ($IS_SHOWING_LOGIN ? "login" : "")) . "\">\n";

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# H E A D E R
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

echo "<div id=\"header\">" .
	"<div id=\"header2\">" .
		"<p><a href=\"http://validator.w3.org/check?uri=referer\">XHTML</a> | <a href=\"http://jigsaw.w3.org/css-validator/check/referer\">CSS</a></p>" .
		($PAGE_COMPACT ? "" : "<h1>: " . $PAGE_NAME . "</h1>") .
	"</div>" .
"</div>";

if ($PAGE_COMPACT) {
	echo "<div class=\"compactheader\"><h1>" . $PAGE_NAME . "</h1></div>";
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# N A V I G A T I O N
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if (!$PAGE_COMPACT && !$IS_SHOWING_LOGIN) {
	echo "<div id=\"nav\">\n";

	# Top level pages
	$top_level_pages = $PAGES -> getChildrenOfPage("");

	# If navigation items found
	if (count($top_level_pages) > 0) {

		echo "<ul>";

		# For each
		foreach ($top_level_pages -> getPageIDs() as $nav_page_id) {

			# Get page details
			$nav_page = $top_level_pages -> getPage($nav_page_id);

			# Get list of groups authorized to view this page
			$nav_page_authorized = explode(",", $nav_page -> getData("p_access"));
			
			# Get List of groups of users
			$nav_group_authorized= explode(",", $USER -> getGroup());

			# Ensure it can be viewed at current authorization
			$nav_page_authorized = (findArrayInArray($nav_page_authorized, $nav_group_authorized) !== false);

			# Ensure it's in the navigation
			$nav_page_in_navigation = ($nav_page -> getData("p_innavigation") == "1");

			# Get class for <a> item
			$item_class = ($nav_page -> getID() == $PAGES -> getPageAtDepth($PAGE_ID, 0)) ? "active" : "";

			if ($nav_page_authorized && $nav_page_in_navigation) {

				# Open nav item
				echo "<li class=\"" . $item_class . "\"><a href=\"../" . $nav_page -> getData("p_section") . "/" . $nav_page -> getID() . ".php\">" . $nav_page -> getData("p_name") . "</a></li>";
			}
		}

		echo "</ul>\n";

	} else {

		echo "<p>No navigation found!</p>\n";
	}

	# Close navigation
	echo "</div>\n";
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# S U B - N A V I G A T I O N
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Active top-level page
$second_level_pages = $PAGES -> getChildrenOfPage($PAGES -> getPageAtDepth($PAGE_ID, 0));

# Set no-sidebar var
$NO_SIDEBAR = true;

# Get subnav text
$subnav_output = "";

if (count($second_level_pages -> getPageIDs()) > 0 && !$PAGE_COMPACT) {

	$subnav_output .= "<div id=\"subnav\"><div id=\"subnav2\">\n<ul>\n";

	foreach ($second_level_pages -> getPageIDs() as $sub_page_id) {

		# Get page details
		$sub_page = $second_level_pages -> getPage($sub_page_id);

		# Item class
		$item_class = ($sub_page -> getID() == $PAGES -> getPageAtDepth($PAGE_ID, 1)) ? "active" : "";

		# Ensure it's in the navigation
		$sub_page_in_navigation = ($sub_page -> getData("p_innavigation") == "1");

		if ($sub_page_in_navigation) {

			# Add page
			$subnav_output .= "<li class=\"" . $item_class . "\"><a href=\"../" . $sub_page -> getData("p_section") . "/" . $sub_page -> getID() . ".php\">" . $sub_page -> getData("p_name") . "</a></li>";

			$NO_SIDEBAR = false;
		}
	}

	$subnav_output .= "</ul>\n</div>\n</div>\n";
}

if (!$NO_SIDEBAR && !$IS_SHOWING_LOGIN) {
	echo $subnav_output;
}

# Container
echo "<div id=\"container\">";


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# M E S S A G E S
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$messages_output = "";
if (count($MESSAGE_ARRAY) > 0) {

	$messages_output .= "<div id=\"messages\" class=\"messages\">\n<ul>\n";

	foreach ($MESSAGE_ARRAY as $message) {
		$messages_output .= "<li class=\"messagetype" . $message[1] . "\">" . $message[0] . "</li>";
	}

	$messages_output .= "</ul>\n</div>\n";
}


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# M A I N
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "<div id=\"maincontent\" class=\"contentdiv\">";

# If not logging in, show messages now
if (!$IS_SHOWING_LOGIN) {
	echo $messages_output;
}

# Primary Output
echo parseFlashXML($PAGE_CONTENT);

# If logging in, show messages now
if ($IS_SHOWING_LOGIN) {
	echo $messages_output;
}



# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# E R R O R S
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if (count($ERROR_ARRAY) > 0 && $SHOW_ERROR_FEEDBACK) {

	echo "\n\n<div id=\"errors\" class=\"messages\">\n";
	echo "<h2>Errors (" . count($ERROR_ARRAY) . ")</h2>\n";
	echo "<ul>";

	foreach ($ERROR_ARRAY as $error) {
		echo "<li class=\"messagetype" . $error[1] . "\">" . $error[0] . "</li>";
	}

	echo "</ul>\n</div>\n";
}



# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# S Q L   Q U E R I E S
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if (count($SQL_ARRAY) > 0 && $SHOW_SQL_FEEDBACK) {

	echo "\n\n<div id=\"sqlqueries\" class=\"messages\">\n";
	echo "<h2>SQL Queries (" . count($SQL_ARRAY) . ")</h2>\n";
	echo "<ul>";

	foreach ($SQL_ARRAY as $sql_query) {
		echo "<li>" . $sql_query . "</li>";
	}

	echo "</ul>\n</div>\n";
}

echo "</div>";

# Close container
echo "</div>\n";


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# F O O T E R
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "<div id=\"footer\">\n";
echo "<div id=\"footerbar\"></div>";
if (!$PAGE_COMPACT) {
	echo "<p>Copyright &copy; Zone4 Digital Media | " . ($SITE_ID == "site" ? "<a href=\"../admin/adminhome.php\">admin</a>" : "<a href=\"../site/index.php\">site</a>");
	if ($USER -> isLoggedIn()) {
		echo " | Logged in as <strong>" . $USER -> getFirstName() . " " . $USER -> getLastName() . "</strong> (" . $USER -> getGroupName() . ") (<a href=\"?logout=1\">logout</a> | <a href=\"../site/userprefs.php\">prefs</a>)";
	}
	echo " | Editor: " . $EDITOR_VERSION . "</p>\n";
	
} else {
	echo "<p>Copyright &copy; Zone4 Digital Media</p>\n";
}
echo "</div>\n";


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# E N D
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "</body>\n";
echo "</html>";

?>